package com.limao.CacheManager;

import com.Hazelcast.Cache;
import com.Hazelcast.CacheFactory;
import com.limao.DBDataClass.SysVersionDataClass;
import com.limao.DBProvider.CrowdVersonProvider;
import com.limao.Tool.CacheClass;
import com.limao.cache.BasicModule;

public class Verson_CacheManager  extends BasicModule{

	private CrowdVersonProvider provider;
	
	private static Verson_CacheManager instance;

    public static Verson_CacheManager getInstance() {
        return instance;
    }
    
    private Cache<String, SysVersionDataClass> Verson_ManagerCache;

    public Verson_CacheManager() {
    	super("Verson_CacheManager");
    	Verson_ManagerCache = CacheFactory.createCache("cd_versonCache");
        initProvider();
    }
    
    @Override
	public void initialize() {
        super.initialize();
        instance=this;
    }
    
    public void ClearObjectCache(String name)
    {
    	Verson_ManagerCache.remove(name);
    }   
    
    //**************************************************************************
 
    //取对应客户端的版本号
    public SysVersionDataClass Load_Verson(String name)
    {
    	if(CacheClass.isEmpty(name)) return null;
    	SysVersionDataClass obj=Verson_ManagerCache.get(name);
    	if(obj==null)
    	{
    		obj=provider.Load_VersonByName(name);
    		if(obj!=null)
    			Verson_ManagerCache.put(obj.name, obj);
    	}
  
    	return obj;
    }  
   
   //*************************************

    private void initProvider() {
        if (provider == null ) {
            try {
                provider =CrowdVersonProvider.getInstance();
            }
            catch (Exception e) {
            	e.printStackTrace();
            }
        }
    }

}
